package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import com.sky.vo.OrderVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

/**
 * @author : jiang
 * @date : 2023/10/21 16:06
 */
@Mapper
public interface OrderMapper {

    /**
     * 新增订单
     * @param orders
     */
    void insert(Orders orders);

    /**
     * 根据订单号和用户id查询订单
     * @param orderNumber
     * @param userId
     * @return
     */
    @Select("select * from orders where number = #{orderNumber} and user_id= #{userId}")
    Orders getByNumberAndUserId(String orderNumber, Long userId);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);

    /**
     * 查询历史订单
     * @param dto
     * @return
     */

    Page<OrderVO> pageHistory(OrdersPageQueryDTO dto);

    /**
     * 订单搜索
     * @param ordersPageQueryDTO
     * @return
     */
    Page<Orders> page(OrdersPageQueryDTO ordersPageQueryDTO);

    /**
     * 根据订单id查询订单
     * @param id
     * @return
     */
    @Select("select * from orders where id = #{id}")
    Orders getOrderById(Long id);

    /**
     * 待接单数量
     * @return
     */
    @Select("select count(*) from orders where status = '2'")
    Integer getToBeConfirmed();

    /**
     * 派送中
     * @return
     */
    @Select("select count(*) from orders where status = '4'")
    Integer getDeliveryInProgress();

    /**
     * 待派送
     * @return
     */
    @Select("select count(*) from orders where status = '3'")
    Integer getConfirmed();
}
